package com.buluo.web.controller

import com.buluo.entity.User
import com.buluo.model.BuiMenu
import com.buluo.service.ResourceService
import com.buluo.service.UserService
import com.buluo.web.bind.annotation.CurrentUser
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.RequestMapping

/**
 * Created by sunhao on 2016/12/15.
 */
@Controller
class IndexController {

    @Autowired
    UserService userService


    @Autowired
    ResourceService resourceService

    @RequestMapping("/")
    public String index(@CurrentUser User loginUser, Model model) {
        Set<String> permissions = this.userService.findPermissions(loginUser.getUserName())
        BuiMenu buiMenu = this.resourceService.getBuiMenuConfig(permissions)
        model.addAttribute("navList", buiMenu.titles)
        model.addAttribute("realName", loginUser.realName)
        model.addAttribute("config", buiMenu.config)
        return "index";
    }

}
